<template>
    <div class="flexbox flexcolumn height_100" v-loading="loading" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0)">
        <div class="flex over_box">
            <el-form label-position='left' label-width="100px" size="small" :model="addForm" :hide-required-asterisk='true' ref="addForm" :rules="addRules" class="add_form">
                <TaskModel ref="task_ref" :addForm="addForm" :userList="userList" @setSessionStorage="setSessionStorage"/>
            </el-form>
        </div>
        <div class="project_footer com_box flexbox flexcenter">
            <el-button type="primary" class="el-button-width" size="small" @click="submitForm('addForm')" :loading="loading" :disabled='loading'>保存</el-button>
            <el-button class="el-button-width" size="small" plain @click="$router.go(-1)">返回</el-button>
        </div>
    </div>
</template>

<script>
import TaskModel from './TaskModel'
export default {
    components: {
        TaskModel
    },
    name: "",
    data() {
        return {
            loading: false,
            addForm: {
                id:"",
                media_worker: "",
                content_worker: "",
                project_manager: "",
                aweme_headimg:"",
                aweme_name: "",
                aweme_id: "",
                task_id: "",
                aweme_price: "",
                aweme_ratio: "",
                online_date: "",
                inspect_date: "",
                getmoney_date: "",
                order_date:"",
                star_id:"",
                star_name:"",
                account_type: 1,
                screenshot: "",
                msg_type:1,
                pay_body:"",
                getmoney_body:"",
                is_out_invoice:0,
                aweme_service_type:1,
                aweme_service:"",
                orderList:[
                    // {
                    //     "star_name": "倍轻松官方旗舰店-极创-星图",
                    //     "star_id": "1757955061560328",
                    //     "nick_name": "郎佳子彧",
                    //     "author_id": "6766511405030965256",
                    //     "avatar_uri": "https://p11.douyinpic.com/aweme/1080x1080/aweme-avatar/mosaic-legacy_317d3000759750d2fa59a.jpeg?from=4010531038",
                    //     "order_price": 8400,
                    //     "order_name": "倍轻松neck5-郎佳子彧",
                    //     "order_id": "7224540794588233787", //task_id
                    //     "create_time": "1682094487",
                    //     "audit_status": 4,
                    //     "release_time": "1682748018", //online_date
                    //     "finish_time": "1683352822" //inspect_date
                    // }
                ],
                orderInfo:{}
            },
            addRules: {
                checkFloat: [
                    {
                        pattern:
                            /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/,
                        required: true,
                        message: "请输入正确数值",
                        trigger: ["blur", "change"],
                    },
                ],
            },
            userList: [],
        };
    },
    created() {
        this.getUserList();
        this.getDetails()
    },
    methods: {
        //获取详情
        async getDetails() {
            this.loading = true
            const { data: res } = await this.$http.post(
                "fxdata/revenue/revenueFind",
                {
                    id:this.$route.query.id
                }
            );
            if (res.code !== 200) {
                this.loading = false
                this.$message.error(res.msg);
                return;
            } else {
                this.loading = false
                this.addForm = res.data
                this.addForm.orderList = []
                this.addForm.orderInfo = {}
                // if(res.data.msg_type==1){
                //     this.$refs.task_ref.getOrder(this.addForm.aweme_name,this.addForm.project_id)
                // }
            }
        },


        //获取人员
        async getUserList() {
            const { data: res } = await this.$http.post(
                "fxdata/revenue/projectUserList",
                {
                    id:this.$route.query.project_id
                }
            );
            if (res.code !== 200) {
                this.$message.error(res.msg);
                return;
            } else {
                this.userList = res.data;
            }
        },
        
        // 提交添加
        submitForm(formName) {
            this.$refs[formName].validate(async (valid) => {
                if (valid) {
                    let subForm = JSON.parse(JSON.stringify(this.addForm))
                    delete subForm.orderList
                    delete subForm.orderInfo
                    this.loading = true;
                    const { data: res } = await this.$http.post(
                        "fxdata/revenue/revenueEdit",
                        this.addForm
                    );
                    if (res.code !== 200) {
                        this.$message.error(res.msg);
                        this.loading = false;
                        return;
                    } else {
                        this.$message({
                            message: "保存成功！",
                            type: "success",
                        });
                        this.loading = false;
                        this.$router.go(-1);
                    }
                } else {
                    this.loading = false;
                    return false;
                }
            });
        },

        // 缓存
        setSessionStorage() {
           
        },
    },
};
</script>


<style scoped>
.project_footer {
    padding: 0 20px;
    height: 72px;
}
.pd_box {
    padding: 0 20px;
    overflow: hidden;
    margin-bottom: 12px;
}
.pro_title {
    font-weight: bold;
    font-size: 16px;
    height: 56px;
    line-height: 56px;
}
</style>


